package io.renren.modules.wx.service.impl;

import io.renren.modules.wx.entity.CourseEntity;
import io.renren.modules.wx.entity.StudentEntity;
import io.renren.modules.wx.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.wx.dao.CourseEvaluationDao;
import io.renren.modules.wx.entity.CourseEvaluationEntity;
import io.renren.modules.wx.service.CourseEvaluationService;


@Service("courseEvaluationService")
public class CourseEvaluationServiceImpl extends ServiceImpl<CourseEvaluationDao, CourseEvaluationEntity> implements CourseEvaluationService {

    @Autowired
    private StudentService studentService;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CourseEvaluationEntity> page = this.page(
                new Query<CourseEvaluationEntity>().getPage(params),
                new QueryWrapper<CourseEvaluationEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<CourseEvaluationEntity> getEvaluationByCourseId(Integer courseId) {
        List<CourseEvaluationEntity> lists = baseMapper.selectList(new QueryWrapper<CourseEvaluationEntity>().eq("course_id",courseId));
        List<CourseEvaluationEntity> res =  lists.stream().map((list)->{
            StudentEntity student = studentService.getById(list.getStudentId());
            list.setFaceImg(student.getFaceImg());
            list.setStudentName(student.getUsername());
            return list;
        }).collect(Collectors.toList());
        return res;
    }


}
